package com.murray.shop.background.controller;

import com.murray.shop.background.pojo.Orders;
import com.murray.shop.background.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author Murray
 * @Date 2021/8/21
 * @Time 13:44
 * @Descirption 用于处理订单
 */
@Controller
@RequestMapping(value = "/orders")
public class OrderController {

    @Autowired
    OrdersService ordersService;

    @RequestMapping(value = "/orderList")
    public ModelAndView orderList() {

        List<Orders> orders = ordersService.selectOrdersList();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("orderList");
        modelAndView.addObject("ordersList", orders);
        return modelAndView;
    }

    @RequestMapping("/deliverGoods")
    public ModelAndView deliverGoods(Integer orderId) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("deliverGoods");
        modelAndView.addObject("orderId",orderId);
        return modelAndView;
    }

    @RequestMapping(value = "/submitDeliverGoods")
    public String submitDeliverGoods(@RequestParam(value = "orderId",required = true) Integer orderId, String shipName, String shipNumber) {
        //修改订单快递信息
        ordersService.updateOrder(orderId, shipName, shipNumber);
        //返回订单列表页
        return "redirect:/orders/orderList";
    }


}
